import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import Home from "../views/home/index.vue";

//添加活动页路由
const promotionList = [
  "teamBuy",
  "christmas",
  "electrical",
  "haiActivity",
  "country",
  "doubleEleven",
  "giftBag",
  "monthly",
  "year",
  "ornaments",
  "summer",
]; //'lover','queen','giveAnEncore','motherDay',
const promotion: {
  path: string;
  name: string;
  component: () => Promise<any>;
  meta: { keepAlive: boolean };
}[] = [];
promotionList.forEach((item) => {
  promotion.push({
    path: "/" + item,
    name: item,
    component: () => import("../views/promotion/" + item + ".vue"),
    meta: {
      keepAlive: true, // 是否使用 keep-alive
    },
  });
});

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "Home",
    redirect: "/home",
  },
  {
    path: "/home",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: Home,
    meta: {
      keepAlive: true, // 是否使用 keep-alive
    },
  },
  {
    path: "/searchbefore",
    name: "searchbefore",
    component: () =>
      import(
        /* webpackChunkName: "product" */ "../views/home/searchbefore.vue"
      ),
    meta: {
      keepAlive: false, // 是否使用 keep-alive
    },
  },
  {
    path: "/search",
    name: "search",
    component: () =>
      import(/* webpackChunkName: "product" */ "../views/home/search.vue"),
    meta: {
      keepAlive: true, // 是否使用 keep-alive
    },
  },
  {
    path: "/product",
    name: "product",
    component: () =>
      import(/* webpackChunkName: "product" */ "../views/product/index.vue"),
    meta: {
      keepAlive: false, // 是否使用 keep-alive
    },
  },
  {
    path: "/gallery",
    name: "gallery",
    component: () => import("../views/gallery/index.vue"),
    meta: {
      keepAlive: true, // 是否使用 keep-alive
    },
  },
  {
    path: "/cart",
    name: "cart",
    component: () => import("../views/cart/index.vue"),
    meta: {
      keepAlive: false, // 是否使用 keep-alive
    },
  },

  {
    path: "/teamBuyInfo",
    name: "teamBuyInfo",
    component: () => import("../views/product/teamBuyInfo.vue"),
    meta: {
      keepAlive: false, // 是否使用 keep-alive
    },
  },
  {
    path: "/rushbuy",
    name: "rushbuy",
    component: () => import("../views/promotion/rushbuy.vue"),
    children: [
      {
        path: "hieleven",
        name: "hieleven",
        component: () => import("../views/promotion/rushbuy/hieleven.vue"),
      },
      {
        path: "peoplebuy",
        name: "peoplebuy",
        component: () => import("../views/promotion/rushbuy/peoplebuy.vue"),
      },
    ],
    meta: {
      keepAlive: true, // 是否使用 keep-alive
    },
  },

  ...promotion,
];

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes,
});

export default router;
